﻿using System;
using IterationLife.System.ExternalIdentity;
using IterationLife.System.Models;
using Util.Iocs;

namespace IterationLife.System.Services
{
    /// <summary>
    /// 提供用户管理相关API
    /// </summary>
    public interface IUserManager:IDependency
    {
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="phone"></param>
        /// <param name="verifyCode"></param>
        /// <returns></returns>
        User Register(string username, string password, string phone = null,string verifyCode = null);
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="user"></param>
        void Delete(User user);
        /// <summary>
        /// 通过账号找到用户
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        User FindUserByAccount(string account);
        /// <summary>
        /// 添加外部用户
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="externalUserId"></param>
        /// <param name="externalCode"></param>
        void AddExternalUser(Guid userId, string externalUserId, string externalCode);

        /// <summary>
        /// 验证密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        bool VerifyPassword(User user, string password);
        User FindUserByExternalLogin(string loginProvider, string externalId);

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="currentPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        bool ChangePassword(User user, string currentPassword, string newPassword);
        void CreateUserByUserInfo(string provider, ExternalUserInfo userInfo);

        /// <summary>
        /// 通过验证码修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newPassword"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        bool ChangePasswordByToken(User user, string newPassword, string token);
        /// <summary>
        /// 修改邮箱
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newEmail"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        bool ChangeEmail(User user, string newEmail, string token);
        bool CheckUserNameExists(string username);

        /// <summary>
        /// 修改手机号
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newPhoneNumber"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        bool ChangePhoneNumber(User user, string newPhoneNumber, string token);
        void SendRegisterCode(string phone);
        void SendGetBackPasswordCode(string phone);
        void GetBackPassword(string phone, string newPassword, string verifyCode);
    }
}
